using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace GameEditor.Common.Controls
{
    public class ColorPreview : Control
    {
        private SolidBrush brush1 = new SolidBrush(Color.Black);
        private SolidBrush brush2 = new SolidBrush(Color.Black);

        public Color Color1
        {
            get { return brush1.Color; }
            set { brush1.Color = value; }
        }

        public Color Color2
        {
            get { return brush2.Color; }
            set { brush2.Color = value; }
        }
        public ColorPreview()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
        }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            Rectangle rect = new Rectangle(Point.Empty, new Size(Width - 1, Height - 1));
            Rectangle r1 = new Rectangle(0, 0, Width / 2, Height);
            Rectangle r2 = new Rectangle(Width / 2, 0, Width / 2, Height);

            //draw background

            int cellSize = 5;
            for (int y = 0; y < rect.Height; y += cellSize)
            {
                bool useGrayBrush = (y & 1) == 1;
                for (int x = 0; x < rect.Width; x += cellSize)
                {
                    useGrayBrush = !useGrayBrush;
                    Brush brush = useGrayBrush ? Brushes.Gray : Brushes.White;
                    g.FillRectangle(brush, new Rectangle(x, y, cellSize, cellSize));
                }
            }

            //draw first color
            g.FillRectangle(brush1, r1);
            g.FillRectangle(brush2, r2);



            //draw border
            g.DrawRectangle(Pens.Black, rect);
        }
    }
}
